import django_filters
from .models import Notification, EmailLog, SystemAnnouncement


class NotificationFilter(django_filters.FilterSet):
    notification_type = django_filters.ChoiceFilter(
        choices=['info', 'warning', 'error', 'success']
    )
    priority = django_filters.ChoiceFilter(
        choices=['low', 'medium', 'high', 'urgent']
    )
    is_read = django_filters.BooleanFilter()
    user = django_filters.NumberFilter(field_name='user__id')
    start_date = django_filters.DateFilter(field_name='created_at', lookup_expr='gte')
    end_date = django_filters.DateFilter(field_name='created_at', lookup_expr='lte')
    
    class Meta:
        model = Notification
        fields = ['notification_type', 'priority', 'is_read', 'user', 
                 'start_date', 'end_date']


class EmailLogFilter(django_filters.FilterSet):
    status = django_filters.ChoiceFilter(choices=['sent', 'failed'])
    template_name = django_filters.CharFilter(field_name='template_name', lookup_expr='icontains')
    start_date = django_filters.DateFilter(field_name='sent_at', lookup_expr='gte')
    end_date = django_filters.DateFilter(field_name='sent_at', lookup_expr='lte')
    
    class Meta:
        model = EmailLog
        fields = ['status', 'template_name', 'start_date', 'end_date']


class SystemAnnouncementFilter(django_filters.FilterSet):
    announcement_type = django_filters.ChoiceFilter(
        choices=['info', 'warning', 'maintenance', 'promotion']
    )
    priority = django_filters.ChoiceFilter(
        choices=['low', 'medium', 'high', 'urgent']
    )
    is_active = django_filters.BooleanFilter()
    start_date = django_filters.DateFilter(field_name='start_date', lookup_expr='gte')
    end_date = django_filters.DateFilter(field_name='end_date', lookup_expr='lte')
    
    class Meta:
        model = SystemAnnouncement
        fields = ['announcement_type', 'priority', 'is_active', 
                 'start_date', 'end_date']
